/*
 * 获取多个随机头像
 * number:index 需要获取的数量
 */
function GetRandomHead(index) {
    RequestGTMC("getPortrait", {},
        function(json) {
            console.log("随机头像 获取成功", json.data);
            // console.log(json);
            // console.log(index, $(".detail_review_content .circle img").eq(index));
            $(".detail_review_content .circle:eq(" + index + ") img").attr('src', (ITSMLINK + json.data));
        });
}

/*
 * 获取多个随机头像
 */
function FillApplicantInfo() {
    $("#service_packing_user").attr('data-cususer', $("#common_myself_name").attr('data-id'));
    $("#service_packing_user .name").val($("#common_myself_name").html()).attr('data-name', $("#common_myself_name").html());
    $("#service_packing_user .code").val($("#common_myself_name").attr('data-code')).attr('data-code', $("#common_myself_name").attr('data-code'));
    $(".common_shadow").addClass('activate').children('.common_popup_applicant').addClass('activate');
    // $(".common_shadow.index").removeClass('activate').children('.common_popup_applicant').removeClass('activate');
}

/*
 * 计算上传数量
 */
function UploadComplete(count) {
    var time = 0,
        InitUpload = function() {
            console.log("Upload Files: " + count);
        };
    AddUpload = function() {
        console.log("Upload times:", ++time);
        if (time >= count) {
            SureCommit();
        }
    };
    return InitUpload();
}

/*
 * 检查输入内容
 * object:$form 要检查的表单的 jQuery 对象
 * bool:popup 确定是否需要弹窗
 */
function CheckServiceContent($form, popup) {
    // 检查
    console.clear();
    var reqstr = undefined;
    $form.find(".itsf_isTxtLength").each(function(index, el) {
        if ($(el).val().trim() !== "" && $(el).val().trim().length > 1000) {
            reqstr = "请限制输入的字数在一千以内";
            // $(el).val("");
            console.log("长度检查", reqstr, $(el).val().trim(), el);
        }
    });
    $form.find(".itsf_isPhoneNo").each(function(index, el) {
        var pattern = /^1[34578]\d{9}$/;
        if ($(el).val().trim() !== "" && !pattern.test($(el).val())) {
            reqstr = "请输入正确的手机号码";
            // $(el).val("");
            console.log("手机检查", reqstr, $(el).val().trim(), el);
        }
    });
    $form.find(".itsf_isTelNo").each(function(index, el) {
        var pattern = /^((\d{3,4}-)|\d{3.4}-)?\d{7,8}$/;
        if ($(el).val().trim() !== "" && !pattern.test($(el).val())) {
            reqstr = "请输入正确的固话号码";
            // $(el).val("");
            console.log("固话检查", reqstr, $(el).val().trim(), el);
        }
    });
    $form.find(".itsf_isContactNo").each(function(index, el) {
        var pattern1 = /^1[34578]\d{9}$/,
            pattern2 = /^((\d{3,4}-)|\d{3.4}-)?\d{7,8}$/;
        if ($(el).val().trim() !== "" && (!pattern1.test($(el).val()) || !pattern2.test($(el).val()))) {
            reqstr = "请输入正确的手机或固话号码";
            // $(el).val("");
            console.log("长号检查", reqstr, $(el).val().trim(), el);
        }
    });
    $form.find(".itsf_isShortNo").each(function(index, el) {
        var pattern = /^\d{3,6}$/;
        if ($(el).val().trim() !== "" && !pattern.test($(el).val())) {
            reqstr = "请输入正确的短号";
            // $(el).val("");
            console.log("短号检查", reqstr, $(el).val().trim(), el);
        }
    });
    $form.find(".itsf_isEmail").each(function(index, el) {
        var pattern = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
        if ($(el).val().trim() !== "" && !pattern.test($(el).val())) {
            reqstr = "请输入正确的邮箱";
            // $(el).val("");
            console.log("邮箱检查", reqstr, $(el).val().trim(), el);
        }
    });
    $form.find(".itsf_isNumber").each(function(index, el) {
        var pattern = /^\d+(\.{1}\d+)?$/;
        if ($(el).val().trim() !== "" && !pattern.test($(el).val())) {
            reqstr = "请输入正确的数量";
            // $(el).val("");
            console.log("数量检查", reqstr, $(el).val().trim(), el);
        }
    });
    $form.find(".itsf_isPrice").each(function(index, el) {
        var pattern = /^\d+(\.{1}\d+)?$/;
        if ($(el).val().trim() !== "" && !pattern.test($(el).val())) {
            reqstr = "请输入正确的金额";
            // $(el).val("");
            console.log("金额检查", reqstr, $(el).val().trim(), el);
        }
    });
    $form.find(".itsf_isPing").each(function(index, el) {
        var pattern = /^[a-z]+$/;
        if ($(el).val().trim() !== "" && !pattern.test($(el).val())) {
            reqstr = "请输入正确的拼音，由小写字母组成";
            // $(el).val("");
            console.log("拼音检查", reqstr, $(el).val().trim(), el);
        }
    });
    $form.find(".requiredprompt").each(function(index0, el0) {
        if ($(el0).parent().find('input[type="checkbox"]:not(.ban)').length > 0 && $(el0).parent().find('input[type="checkbox"]:not(.ban):checked').length === 0) {
            reqstr = "请核对当前表单中必填项是否已全部填写";
            console.log("非空检查", reqstr, $(el0).parent().find('input[type="checkbox"]:not(.ban):checked').length, el0);
        }
        $(el0).parent().find('input:not([type="hidden"]):not([type="checkbox"]):not(.ban)').each(function(index1, el1) {
            if ($(el1).val().trim() === "") {
                reqstr = "请核对当前表单中必填项是否已全部填写";
                console.log("非空检查", reqstr, $(el1).val().trim(), el1);
            }
        });
        $(el0).parent().find('textarea:not(.ban)').each(function(index1, el1) {
            if ($(el1).val().trim() === "") {
                reqstr = "请核对当前表单中必填项是否已全部填写";
                console.log("非空检查", reqstr, $(el1).val().trim(), el1);
            }
        });
        $(el0).parent().find('select:not(.ban)').each(function(index1, el1) {
            if (el1.selectedIndex === 0) {
                reqstr = "请核对当前表单中必填项是否已全部填写";
                console.log("非空检查", reqstr, $(el1).val().trim(), el1);
            }
        });
    });
    // 是否弹窗提示
    if (reqstr !== undefined) {
        if (popup && reqstr === "请核对当前表单中必填项是否已全部填写") {
            // 主要报单弹出非空提示
            ShowVerifyTips(reqstr);
        } else if (reqstr !== "请核对当前表单中必填项是否已全部填写") {
            // 所有报单弹出验证提示
            $form.parent().removeClass('border_active');
            ShowVerifyTips(reqstr);
        } else {
            // 其他报单弹出非空提示
            $form.parent().addClass('border_active');
        }
    }
    return reqstr;
}

// 验证弹窗事件
function ShowVerifyTips(str) {
    if ($(".common_shadow").children('.activate').length > 0) {
        $(".detail_popup_verify").css("background-image", "url(../images/ie8shadow.png)");
    }
    $(".common_shadow").addClass('activate').children(".detail_popup_verify").addClass('activate').find('.word').html(str);
}

// 验证页面控件
function InputDataVerify() {
    if ($(".itsf_isTxtLength").length > 0) {
        isTxtLength();
    }
    if ($(".itsf_isPhoneNo").length > 0) {
        isPhoneNo();
    }
    if ($(".itsf_isTelNo").length > 0) {
        isTelNo();
    }
    if ($(".itsf_isContactNo").length > 0) {
        isContactNo();
    }
    if ($(".itsf_isShortNo").length > 0) {
        isShortNo();
    }
    if ($(".itsf_isEmail").length > 0) {
        isEmail();
    }
    if ($(".itsf_isNumber").length > 0) {
        isNumber();
    }
    if ($(".itsf_isPrice").length > 0) {
        isPrice();
    }
    if ($(".itsf_isPing").length > 0) {
        isPing();
    }
}

// 输入长度
function isTxtLength() {
    $(".itsf_isTxtLength").each(function(index, el) {
        $(el).off('blur').on('blur', function(event) {
            if ($(this).val().trim().length > 1000) {
                $(this).val("");
                ShowVerifyTips("请限制输入的字数在一千以内。");
            }
        });
    });
}

// 手机号码
function isPhoneNo() {
    $(".itsf_isPhoneNo").each(function(index, el) {
        $(el).off('blur').on('blur', function(event) {
            var pattern = /^1[34578]\d{9}$/;
            if (!pattern.test($(this).val())) {
                $(this).val("");
                ShowVerifyTips("请输入正确的手机号码");
            }
        });
    });
}

// 固话号码
function isTelNo() {
    $(".itsf_isTelNo").each(function(index, el) {
        $(el).off('blur').on('blur', function(event) {
            var pattern = /^((\d{3,4}-)|\d{3.4}-)?\d{7,8}$/;
            if (!pattern.test($(this).val())) {
                $(this).val("");
                ShowVerifyTips("请输入正确的固话号码");
            }
        });
    });
}

// 联系号码
function isContactNo() {
    $(".itsf_isContactNo").each(function(index, el) {
        $(el).off('blur').on('blur', function(event) {
            var pattern1 = /^1[34578]\d{9}$/,
                pattern2 = /^((\d{3,4}-)|\d{3.4}-)?\d{7,8}$/;
            if (!pattern1.test($(this).val()) || !pattern2.test($(this).val())) {
                $(this).val("");
                ShowVerifyTips("请输入正确的手机或固话号码");
            }
        });
    });
}

// 联系短号
function isShortNo() {
    $(".itsf_isShortNo").each(function(index, el) {
        $(el).off('blur').on('blur', function(event) {
            var pattern = /^\d{3,6}$/;
            if (!pattern.test($(this).val())) {
                $(this).val("");
                ShowVerifyTips("请输入正确的短号");
            }
        });
    });
}

// 联系邮箱
function isEmail() {
    $(".itsf_isEmail").each(function(index, el) {
        $(el).off('blur').on('blur', function(event) {
            var pattern = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
            if (!pattern.test($(this).val())) {
                $(this).val("");
                ShowVerifyTips("请输入正确的邮箱");
            }
        });
    });
}

// 数量
function isNumber() {
    $(".itsf_isNumber").each(function(index, el) {
        $(el).off('blur').on('blur', function(event) {
            var pattern = /^\d+(\.{1}\d+)?$/;
            if (!pattern.test($(this).val())) {
                $(this).val("");
                ShowVerifyTips("请输入正确的数量");
            }
        });
    });
}

// 金额
function isPrice() {
    $(".itsf_isPrice").each(function(index, el) {
        $(el).off('blur').on('blur', function(event) {
            var pattern = /^\d+(\.{1}\d+)?$/;
            if (!pattern.test($(this).val())) {
                $(this).val("");
                ShowVerifyTips("请输入正确的金额");
            }
        });
    });
}

// 拼音
function isPing() {
    $(".itsf_isPing").each(function(index, el) {
        $(el).off('blur').on('blur', function(event) {
            var pattern = /^[a-z]+$/;
            if (!pattern.test($(this).val())) {
                $(this).val("");
                ShowVerifyTips("请输入正确的拼音，由小写字母组成");
            }
        });
    });
}

/*
 * 提交所有数据报单
 */
function SureCommit() {
    var entire = new Array(),
        single = new Object(),
        defaultid = $(".service_packing_submit[data-default]").attr('data-default');
    console.clear();
    $(".service_packing_submit:not(.fake)").each(function(index0, el0) {
        console.log("SureCommit", index0, el0);
        // 设置单个表单的数据
        entire[index0] = {
            "itemId": $(el0).find('#itemId').attr('value'),
            "reqType": $(el0).attr('data-form'),
            "cusUserId": $("#service_packing_user").attr('data-cususer'),
            "serviceAddressId": $("#detail_service_address").attr('data-address'),
            "reqData": new Array()
        }
        if (!entire[index0].itemId) {
            console.log("表单信息 itemId 获取失败", entire[index0].itemId);
        } else if (!entire[index0].reqType) {
            console.log("表单信息 reqType 获取失败", entire[index0].reqType);
        } else if (!entire[index0].serviceAddressId) {
            console.log("表单信息 serviceAddressId 获取失败", entire[index0].serviceAddressId);
        }
        // 填充单表单所有数据
        $(el0).find('tr').each(function(index1, el1) {
            $(el1).find('input:not(.ban)').each(function(index2, el2) {
                if ($(el2).attr('name')) {
                    single = {
                        "name": $(el2).attr('name'),
                        "value": $(el2).val(),
                        "data-valid": $(el2).attr('data-valid'),
                        "hidden": ($(el2).attr('hidden') === "hidden" ? "true" : undefined)
                    };
                    if (typeof(single["name"]) === "undefined") {
                        console.log("name 获取失败", single["name"], single);
                    }
                    if (typeof(single["value"]) === "undefined") {
                        // 可能是勾选框
                        if ($(el2).prop('checked')) {
                            single["value"] = "checked";
                        }
                        if (typeof(single["value"]) === "undefined") {
                            console.log("value 获取失败", single["value"], single);
                        }
                    }
                    if (typeof(single["data-valid"]) === "undefined") {
                        // 获取数据标题
                        single["data-valid"] = $(el2).parents('tr').find('td.first').html();
                        if (typeof(single["data-valid"]) === "undefined") {
                            console.log("data-valid 获取失败", single["data-valid"], single);
                        }
                    }
                    if (typeof(single["hidden"]) === "undefined") {
                        // 可能已经隐藏
                        if ($(el2).attr('type') === "hidden") {
                            single["hidden"] = "true";
                        } else {
                            // console.log("hidden 获取失败", single["hidden"], single);
                            single["hidden"] = "false";
                        }
                    }
                    if ($(el2).attr('type') === 'radio' || $(el2).attr('type') === 'checkbox') {
                        console.log($(el2).attr('type'), $(el2).is(':checked'));
                        if ($(el2).is(':checked')) {
                            entire[index0].reqData.push(single);
                            console.log(($(el2).attr('type') === 'radio' ? '单选框' : '多选框'), single);
                        }
                    } else {
                        entire[index0].reqData.push(single);
                    }
                } else {
                    console.log("该控件没有 name 属性", el2);
                }
            });
            $(el1).find('textarea:not(.ban)').each(function(index3, el3) {
                if ($(el3).attr('name')) {
                    single = {
                        "name": $(el3).attr('name'),
                        "value": $(el3).val(),
                        "data-valid": $(el3).attr('data-valid'),
                        "hidden": ($(el3).attr('hidden') === "hidden" ? "true" : undefined)
                    };
                    if (typeof(single["name"]) === "undefined") {
                        console.log("name 获取失败", single["name"], single);
                    }
                    if (typeof(single["value"]) === "undefined") {
                        // 可能是勾选框
                        if ($(el3).prop('checked')) {
                            single["value"] = "checked";
                        }
                        if (typeof(single["value"]) === "undefined") {
                            console.log("value 获取失败", single["value"], single);
                        }
                    }
                    if (typeof(single["data-valid"]) === "undefined") {
                        // 获取数据标题
                        single["data-valid"] = $(el3).parents('tr').find('td.first').html();
                        if (typeof(single["data-valid"]) === "undefined") {
                            console.log("data-valid 获取失败", single["data-valid"], single);
                        }
                    }
                    if (typeof(single["hidden"]) === "undefined") {
                        // 可能已经隐藏
                        if ($(el3).attr('type') === "hidden") {
                            single["hidden"] = "true";
                        } else {
                            // console.log("hidden 获取失败", single["hidden"], single);
                            single["hidden"] = "false";
                        }
                    }
                    console.log("文本框", single);
                    entire[index0].reqData.push(single);
                } else {
                    console.log("该控件没有 name 属性", el3);
                }
            });
            $(el1).find('select:not(.ban)').each(function(index4, el4) {
                if ($(el4).attr('name')) {
                    single = {
                        "name": $(el4).attr('name'),
                        "value": $(el4).find("option:selected").text(),
                        "data-valid": $(el4).attr('data-valid'),
                        "hidden": ($(el4).attr('hidden') === "hidden" ? "true" : undefined)
                    };
                    if (typeof(single["name"]) === "undefined") {
                        console.log("name 获取失败", single["name"], single);
                    }
                    if (typeof(single["value"]) === "undefined") {
                        // 可能是勾选框
                        if ($(el4).prop('checked')) {
                            single["value"] = "checked";
                        }
                        if (typeof(single["value"]) === "undefined") {
                            console.log("value 获取失败", single["value"], single);
                        }
                    }
                    if (typeof(single["data-valid"]) === "undefined") {
                        // 获取数据标题
                        single["data-valid"] = $(el4).parents('tr').find('td.first').html();
                        if (typeof(single["data-valid"]) === "undefined") {
                            console.log("data-valid 获取失败", single["data-valid"], single);
                        }
                    }
                    if (typeof(single["hidden"]) === "undefined") {
                        // 可能已经隐藏
                        if ($(el4).attr('type') === "hidden") {
                            single["hidden"] = "true";
                        } else {
                            // console.log("hidden 获取失败", single["hidden"], single);
                            single["hidden"] = "false";
                        }
                    }
                    console.log("下拉框", single);
                    entire[index0].reqData.push(single);
                } else {
                    console.log("该控件没有 name 属性", el3);
                }
            });
        });
    });
    console.log(entire);
    console.log(Object.prototype.toString.call(entire));
    single = JSON.stringify(entire)
    console.log(single);
    console.log(JSON.parse(single));
    RequestGTMC("requestSaveOrUpdate", {
            reqData: single
        },
        function(json) {
            console.log("服务报单提交成功");
            console.log(json);
            if (json.success && json.success === true) {
                // $(".common_shadow").addClass('activate').children(".detail_popup_verify").addClass('activate').find('.word').html("报单成功");
                window.location.href = "terms_adress.html?code=" + json.data.code + "&tier=" + GetUrlParam("tier");
            } else {
                $(".common_shadow").addClass('activate').children(".detail_popup_verify").addClass('activate fail');
                $(".detail_popup_verify .word").html("报单失败，请及时与IT服务台联系，联系电话：020-39398800。");
                $(".detail_popup_verify .back a").attr('href', 'index.html').html("返回首页");
            }
        },
        function() {
            console.log("服务报单提交失败");
        },
        function() {
            console.log("服务报单提交完成");
        });
}

/*
 * 先上传文件
 */
function SubmitAllFormData() {
    if ($(".common_file_upload .upload_list li").length > 0) {
        $("body").prepend('<div class="common_load full"><img src="../images/loading.gif"></div>');
        var num = $(".common_file_upload .upload_list li").length;
        if ($(".service_packing_submit.fake").length > 0) {
            // 多个报单
            console.log(num, $(".common_file_upload .upload_list li").length, $(".service_packing_submit.fake .upload_list li").length);
            num -= $(".service_packing_submit.fake .upload_list li").length;
            var up = UploadComplete(num);
            $("#service_packing_other .upload_list li .hid").trigger('click');
        } else {
            console.log(num, $(".common_file_upload .upload_list li").length, $(".service_packing_submit.fake .upload_list li").length);
            // 单个报单
            var up = UploadComplete(num);
            $(".upload_list li .hid").trigger('click');
        }
    } else {
        $("body").prepend('<div class="common_load full"><img src="../images/loading.gif"></div>');
        SureCommit();
    }
}

/*
 * 点击按需不断加载评论
 */
function LoadAppraise(types) {
    var array = ["rb0", "rb3", "rb2", "rb1"],
        elect = 0,
        nonce = 0,
        SetType = function() {
            if (types) {
                console.log("确认报单评论类型", types);
                RequestGTMC("listCustomerComment", {
                    reqType: types,
                    state: 0,
                    page: 1,
                    row: 1
                }, function(json) {
                    console.log("评论总数 获取成功", json);
                    if (json.total) {
                        $(".detail_review_content label[for='rb0'] span").html("全部(" + json.total + ")");
                        $("#service_packing_info .card li:eq(1)").html('累计评价<em>' + json.total + '</em>');
                    }
                    AddDoneCount();
                });
                RequestGTMC("listCustomerComment", {
                    reqType: types,
                    state: 3,
                    page: 1,
                    row: 1
                }, function(json) {
                    console.log("好评总数 获取成功", json);
                    if (json.total) {
                        $(".detail_review_content label[for='rb1'] span").html("好评(" + json.total + ")");
                    } else {
                        $(".detail_review_content label[for='rb1'] span").html("好评(0)");
                    }
                    AddDoneCount();
                });
                RequestGTMC("listCustomerComment", {
                    reqType: types,
                    state: 2,
                    page: 1,
                    row: 1
                }, function(json) {
                    console.log("中评总数 获取成功", json);
                    if (json.total) {
                        $(".detail_review_content label[for='rb2'] span").html("中评(" + json.total + ")");
                    } else {
                        $(".detail_review_content label[for='rb2'] span").html("中评(0)");
                    }
                    AddDoneCount();
                });
                RequestGTMC("listCustomerComment", {
                    reqType: types,
                    state: 1,
                    page: 1,
                    row: 1
                }, function(json) {
                    console.log("差评总数 获取成功", json);
                    if (json.total) {
                        $(".detail_review_content label[for='rb3'] span").html("差评(" + json.total + ")");
                    } else {
                        $(".detail_review_content label[for='rb3'] span").html("差评(0)");
                    }
                    AddDoneCount();
                });
            }
        },
        Request = function() {
            console.log("选择的是", elect, array[elect], "页码", nonce);
            // 获取服务评价详情
            RequestGTMC("listCustomerComment", {
                    reqType: types,
                    state: elect,
                    page: nonce,
                    row: 6
                },
                function(json) {
                    console.log("评价详情 获取成功");
                    console.log(json);
                    /*if (json.total) {
                        $("#service_packing_info .card li:eq(1)").html('累计评价<em>' + json.total + '</em>');
                    }*/
                    if (json.content && json.content.length > 0) {
                        var val, num, sub, str = '',
                            $cont = $("#service_packing_info .detail_review_content .res");
                        for (val = 0, num = 0; val < json.content.length; val++) {
                            str += '<li class="user"><div class="head"><div class="circle"><img src="' + (json.content[val].photo ? ITSMLINK + json.content[val].photo : '../images/itsf_detail_head1.png') + '"></div><p>' + json.content[val].fullname + '</p></div><div class="comment"><div class="grade"><p>评分</p><ol class="review_star">';
                            num = parseFloat(json.content[val].satisfaction) || 5;
                            for (sub = 1; sub <= 5; sub++) {
                                if (sub <= num) {
                                    str += '<li class="yes"></li>';
                                } else {
                                    str += '<li></li>';
                                }
                            }
                            /*str += '</ol></div><div class="word"><p>内容：</p><span class="appraise">' + json.content[val].customerOpinion + '</span><span class="status">服务：设备调试+设备借用+账号开通+其他</span><div class="time">' + json.content[val].satisfactionDate + '</div></div></div></li>';*/
                            str += '</ol></div><div class="word"><p>内容：</p><span class="appraise">' + json.content[val].customerOpinion + '</span><div class="time">' + json.content[val].satisfactionDate + '</div></div></div></li>';
                            // GetRandomHead(val + 6*(nonce - 1));
                        }
                        if (nonce === 1) {
                            $cont.html(str);
                        } else {
                            $cont.append(str);
                        }
                        console.log(json.page, json.total);
                        if (json.page < json.total) {
                            $("#service_packing_info .detail_bottom_review .more").removeAttr('style');
                        } else {
                            $("#service_packing_info .detail_bottom_review .more").hide();
                        }
                    }
                    AddDoneCount();
                });
        };
    AddAppraise = function() {
        var later = array.indexOf($(".detail_review_content .bar input[type='radio']:checked").attr('id'));
        // 保证字段正常获取
        if (later >= 0) {
            if (later !== elect) {
                // 如果更改评价类型
                elect = later;
                nonce = 1;
                Request();
            } else {
                // 如果没有更改类型
                ++nonce;
                Request();
            }
        }
    };
    NoneAppraise = function() {
        var later = array.indexOf($(".detail_review_content .bar input[type='radio']:checked").attr('id'));
        // 保证字段正常获取
        if (later >= 0) {
            if (later !== elect) {
                // 如果更改评价类型
                elect = later;
                nonce = 1;
            } else {
                // 如果没有更改类型
                ++nonce;
            }
        }
    };
    return SetType();
}
var interim = LoadAppraise(GetUrlParam("type"));

/*
 * 获取多个其他报单
 * 接口类型
 * 报单顺序
 * 报单总数
 */
function GetOtherService(thistype, length) {
    $.ajax({
        url: ITSMLINK + "customer/help/request/api/listRequestByReqType",
        type: "GET",
        dataType: "jsonp",
        async: false,
        jsonp: "callback",
        data: {
            reqType: thistype
        },
        success: (function(json) {
            console.log("其他表单 " + json.data.code + " 获取成功");
            console.log(json);
            if (json.success && json.data) {
                var str, $form = $("#service_packing_other");
                str = '<span class="pic"><i>&#215;</i><img src="' + (json.data.imgSrc ? ITSMLINK + json.data.imgSrc : '../images/termsAd_listImg03.jpg') + '"></span><span class="picName">' + json.data.code + '</span>';
                /*if ($form.html() === "") {
                    str = '<div class="top"><a class="on" href="javascript:">' + str + '</a></div><div class="other on"><dl class="center"><dt><p>' + json.data.code + '</p></dt><dd class="attention">请核对必填项是否已全部填写</dd><dd class="clearfix td_form service_packing_submit" data-form="' + json.data.reqType + '">' + json.data.scriptContent + '</dd></dl><div class="bot"><input type="button" value="下一步" class="next"/></div></div>';
                    $form.html(str);
                } else {
                    $form.children('.top').append('<a href="javascript:">' + str + '</a>');
                    $form.append('<div class="other"><dl class="center"><dt><p>' + json.data.code + '</p></dt><dd class="attention">请核对必填项是否已全部填写</dd><dd class="clearfix td_form service_packing_submit" data-form="' + json.data.reqType + '">' + json.data.scriptContent + '</dd></dl><div class="bot"><input type="button" value="上一步" class="prev"/><input type="button" value="下一步" class="next"/></div></div>');
                }*/
                $form.children('.top').append('<a href="javascript:">' + str + '</a>');
                // 报单加载完成绑定所有事件
                var now = $form.children('.top').children('a').length;
                if (now === length) {
                    if (length === 1) {
                            $form.append('<div class="other on"><dl class="center"><dt><p>' + json.data.code + '</p></dt><dd class="attention">请核对必填项是否已全部填写</dd><dd class="clearfix td_form service_packing_submit" style="max-height: ' + (window.innerHeight - 244) + 'px;" data-form="' + json.data.reqType + '">' + json.data.scriptContent + '<div class="common_file_upload num' + now + '"><span class="upload_title">附件：</span><a href="javascript:" class="upload_sel">上传附件<input id="fileupload" class="num' + now + '" type="file" multiple></a><ul class="upload_list"></ul><span class="upload_tips">支持格式：<br />jpg,gif,png,jpeg,txt,doc,docx,xls,xlsx,pdf,zip,rar,msg,eml,csv,tif</span></div></dd></dl><div class="bot"><input type="button" value="提交报单" class="done"/></div></div>');
                        } else {
                            $form.append('<div class="other"><dl class="center"><dt><p>' + json.data.code + '</p></dt><dd class="attention">请核对必填项是否已全部填写</dd><dd class="clearfix td_form service_packing_submit" style="max-height: ' + (window.innerHeight - 244) + 'px;" data-form="' + json.data.reqType + '">' + json.data.scriptContent + '<div class="common_file_upload num' + now + '"><span class="upload_title">附件：</span><a href="javascript:" class="upload_sel">上传附件<input id="fileupload" class="num' + now + '" type="file" multiple></a><ul class="upload_list"></ul><span class="upload_tips">支持格式：<br />jpg,gif,png,jpeg,txt,doc,docx,xls,xlsx,pdf,zip,rar,msg,eml,csv,tif</span></div></dd></dl><div class="bot"><input type="button" value="上一步" class="prev"/><input type="button" value="提交报单" class="done"/></div></div>');
                        }
                    // 绑定事件
                    BindFormEvent();
                    /*if (roottype.indexOf("pack") === 0) {
                        $form.find('.top a.on i').trigger('click');
                    }*/
                } else if (now === 1) {
                    $form.append('<div class="other on"><dl class="center"><dt><p>' + json.data.code + '</p></dt><dd class="attention">请核对必填项是否已全部填写</dd><dd class="clearfix td_form service_packing_submit" style="max-height: ' + (window.innerHeight - 244) + 'px;" data-form="' + json.data.reqType + '">' + json.data.scriptContent + '<div class="common_file_upload num' + now + '"><span class="upload_title">附件：</span><a href="javascript:" class="upload_sel">上传附件<input id="fileupload" class="num' + now + '" type="file" multiple></a><ul class="upload_list"></ul><span class="upload_tips">支持格式：<br />jpg,gif,png,jpeg,txt,doc,docx,xls,xlsx,pdf,zip,rar,msg,eml,csv,tif</span></div></dd></dl><div class="bot"><input type="button" value="下一步" class="next"/></div></div>').children('.top').children('a:eq(0)').addClass('on');
                    console.log($form.children('.top').children('a:eq(0)'));
                } else {
                    $form.append('<div class="other"><dl class="center"><dt><p>' + json.data.code + '</p></dt><dd class="attention">请核对必填项是否已全部填写</dd><dd class="clearfix td_form service_packing_submit" style="max-height: ' + (window.innerHeight - 244) + 'px;" data-form="' + json.data.reqType + '">' + json.data.scriptContent + '<div class="common_file_upload num' + now + '"><span class="upload_title">附件：</span><a href="javascript:" class="upload_sel">上传附件<input id="fileupload" class="num' + now + '" type="file" multiple></a><ul class="upload_list"></ul><span class="upload_tips">支持格式：<br />jpg,gif,png,jpeg,txt,doc,docx,xls,xlsx,pdf,zip,rar,msg,eml,csv,tif</span></div></dd></dl><div class="bot"><input type="button" value="上一步" class="prev"/><input type="button" value="下一步" class="next"/></div></div>');
                }
                // 上传链接
                var namelist = new Array(),
                    acceptFileTypes = /(jpg|gif|png|jpeg|txt|doc|docx|xls|xlsx|ppt|pptx|pdf|zip|rar|apk|msg|eml|csv|tif)$/i,
                    thissource = $('input[name="itemId"]:eq(' + (now - 1) + ')').val();
                $("#fileupload.num" + now).fileupload({
                    url: ITSMLINK + 'fileUpload?sourceId=' + thissource,
                    autoUpload: false,
                    dataType: "json",
                    add: function(e, data) {
                        // 去重名
                        if (namelist.indexOf(data.files[0].name) === -1) {
                            // 限格式
                            if (acceptFileTypes.test(data.files[0].name.split(".")[data.files[0].name.split(".").length - 1])) {
                                // 限大小
                                if (data.originalFiles[0]['size'] < 15728640) {
                                    $(".common_file_upload.num" + now + " .upload_list").addClass('activate').append('<li><span class="act">' + data.files[0].name + '</span></li>');
                                    $("<a/>").appendTo($(".common_file_upload.num" + now + " .upload_list li:last")).attr({
                                        "href": "javascript:",
                                        "class": "del"
                                    }).on('click', function(event) {
                                        var arrindex = $(this).parent().index();
                                        namelist.splice(arrindex, 1);
                                        $(this).parent().remove();
                                        console.log(namelist, e, data);
                                    });
                                    $("<a/>").appendTo($(".common_file_upload.num" + now + " .upload_list li:last")).attr({
                                        "href": "javascript:",
                                        "class": "hid"
                                    }).on('click', function(event) {
                                        data.submit();
                                    });
                                    namelist.push(data.files[0].name);
                                } else {
                                    $(".common_shadow").addClass('activate').children('.detail_popup_prompt').addClass('activate').find('.word').html("请核对上传文件大小是否超过 15M 。");
                                }
                            } else {
                                $(".common_shadow").addClass('activate').children('.detail_popup_prompt').addClass('activate').find('.word').html("请核对上传文件格式是否符合。");
                            }
                        } else {
                            $(".common_shadow").addClass('activate').children('.detail_popup_prompt').addClass('activate').find('.word').html("请核对上传文件名称是否相同。");
                        }
                        console.log(namelist, e, data);
                        console.log(data.originalFiles[0]['size'], (data.originalFiles[0]['size'] < 15728640), data.files[0].name.split(".")[data.files[0].name.split(".").length - 1], acceptFileTypes.test(data.files[0].name.split(".")[data.files[0].name.split(".").length - 1]), data.files[0].name.split(".").length, data.originalFiles[0]['type']);
                    },
                    done: function(e, data) {
                        console.log("upload succeed", data.files[0].name, data.url);
                        console.log(e, data);
                        AddUpload();
                    }
                });
                console.log("length", length, "child", now, "itemid", thissource);
            }
        })
    });
}

function BindFormEvent() {
    AddDoneCount();
    // 特殊输入校验
    // InputDataVerify();
    // 提交
    $("#service_packing_other").find('.done').off('click').on('click', function(event) {
        /* 验证开始 */
        /*var required = 0;
        $(this).parents('.other').find(".required-tip").each(function(index1, el1) {
            $(el1).parent().find('input:not([type="hidden"]):not(.ban)').each(function(index2, el2) {
                if ($(el2).val() === "") {
                    required = -9999;
                } else {
                    required++;
                }
                console.log("检查", required, $(el2).val(), el2);
            });
            $(el1).parent().find('textarea:not(.ban)').each(function(index3, el3) {
                if ($(el3).val() === "") {
                    required = -9999;
                } else {
                    required++;
                }
                console.log("检查", required, $(el3).val(), el3);
            });
            $(el1).parent().find('select:not(.ban)').each(function(index4, el4) {
                if (el4.selectedIndex === 0) {
                    required = -9999;
                } else {
                    required++;
                }
                console.log("检查", required, $(el4).val(), el4);
            });
        });
        if (required >= 0) {
            //确认提交表单
            FillApplicantInfo();
            $(".common_shadow").removeClass('activate').children('.common_adaptation').removeClass('activate').children('.termsAdress_declaration').removeClass('on');
            $(this).parents('.other').addClass('ok').children('.center').removeClass('border_active');
        } else {
            $(this).parents('.other').removeClass('ok').children('.center').addClass('border_active');
        }*/
        if (CheckServiceContent($(this).parents('.other').find(".service_packing_submit")) === undefined) {
            //确认提交表单
            $(".common_shadow").removeClass('activate').children('.common_adaptation').removeClass('activate').children('.termsAdress_declaration').removeClass('on');
            $(this).parents('.other').addClass('ok').children('.center').removeClass('border_active');
            FillApplicantInfo();
        }
    });
    // 下一步
    $("#service_packing_other").find('.next').off('click').on('click', function(event) {
        /* 验证开始 */
        /*var required = 0;
        $(this).parents('.other').find(".required-tip").each(function(index1, el1) {
            $(el1).parent().find('input:not([type="hidden"]):not(.ban)').each(function(index2, el2) {
                if ($(el2).val() === "") {
                    required = -9999;
                } else {
                    required++;
                }
                console.log("检查", required, $(el2).val(), el2);
            });
            $(el1).parent().find('textarea:not(.ban)').each(function(index3, el3) {
                if ($(el3).val() === "") {
                    required = -9999;
                } else {
                    required++;
                }
                console.log("检查", required, $(el3).val(), el3);
            });
            $(el1).parent().find('select:not(.ban)').each(function(index4, el4) {
                if (el4.selectedIndex === 0) {
                    required = -9999;
                } else {
                    required++;
                }
                console.log("检查", required, $(el4).val(), el4);
            });
        });
        if (required >= 0) {
            $(this).parents('.other').removeClass('on').next('.other').addClass('on').siblings('.top').children('a.on').removeClass('on').next('a').addClass('on');
            $(this).parents('.other').addClass('ok').children('.center').removeClass('border_active');
        } else {
            $(this).parents('.other').removeClass('ok').children('.center').addClass('border_active');
        }*/
        if (CheckServiceContent($(this).parents('.other').find(".service_packing_submit")) === undefined) {
            $(this).parents('.other').removeClass('on').next('.other').addClass('on').siblings('.top').children('a.on').removeClass('on').next('a').addClass('on');
            $(this).parents('.other').addClass('ok').children('.center').removeClass('border_active');
        }
    });
    // 上一步
    $("#service_packing_other").find('.prev').off('click').on('click', function(event) {
        $(this).parents('.other').removeClass('on').prev('.other').addClass('on').siblings('.top').children('a.on').removeClass('on').prev('a').addClass('on');
        // $(this).parents('.other').prev('.other').children('.center').removeClass('border_active');
    });
    // 点击切换
    $("#service_packing_other").children('.top').off('click').on('click', 'a', function(event) {
        var oldindex = $("#service_packing_other .top a.on").index(),
            newindex = $(this).index(),
            required = 0;
        console.log(oldindex);
        /* 验证开始 */
        /*$("#service_packing_other .other").eq(oldindex).find(".required-tip").each(function(index1, el1) {
            $(el1).parent().find('input:not([type="hidden"]):not(.ban)').each(function(index2, el2) {
                if ($(el2).val() === "") {
                    required = -9999;
                } else {
                    required++;
                }
                console.log("检查", required, $(el2).val(), el2);
            });
            $(el1).parent().find('textarea:not(.ban)').each(function(index3, el3) {
                if ($(el3).val() === "") {
                    required = -9999;
                } else {
                    required++;
                }
                console.log("检查", required, $(el3).val(), el3);
            });
            $(el1).parent().find('select:not(.ban)').each(function(index4, el4) {
                if (el4.selectedIndex === 0) {
                    required = -9999;
                } else {
                    required++;
                }
                console.log("检查", required, $(el4).val(), el4);
            });
        });
        if (required >= 0) {
            $("#service_packing_other .other").eq(oldindex).addClass('ok').children('.center').removeClass('border_active');
            if ($("#service_packing_other .other").eq(newindex).hasClass('ok')) {
                $(this).parents('.other').removeClass('on').next('.other').addClass('on').siblings('.top').children('a.on').removeClass('on').next('a').addClass('on');
                $("#service_packing_other .on").removeClass('on');
                $("#service_packing_other .other").eq(newindex).addClass('on').siblings('.top').children().eq(newindex).addClass('on');
            }
        } else {
            $("#service_packing_other .other").eq(oldindex).removeClass('ok').children('.center').addClass('border_active');
        }*/
        if (CheckServiceContent($("#service_packing_other .other").eq(oldindex).find(".service_packing_submit")) === undefined) {
            $("#service_packing_other .other").eq(oldindex).addClass('ok').children('.center').removeClass('border_active');
            if ($("#service_packing_other .other").eq(newindex).hasClass('ok')) {
                $(this).parents('.other').removeClass('on').next('.other').addClass('on').siblings('.top').children('a.on').removeClass('on').next('a').addClass('on');
                $("#service_packing_other .on").removeClass('on');
                $("#service_packing_other .other").eq(newindex).addClass('on').siblings('.top').children().eq(newindex).addClass('on');
            }
        }
    });
    // 删除按钮
    $(".top .pic i").off('click').on('click', function(event) {
        var thisindex = $(this).parent().parent().index(),
            thisnonce = $("#service_packing_other .top .on").index(),
            thiscount = $(this).parents('.top').children('a').length;
        console.log("delete", thisindex, thiscount);
        if (thiscount === 1) {
            $(".common_shadow").removeClass('activate').children('.common_adaptation').removeClass('activate').children('.termsAdress_declaration').removeClass('on');
        }
        // 操作按钮
        if (thisindex === 0) {
            // 第一个
            if (thiscount === 2) {
                // 剩两个
                $("#service_packing_other .other").eq(thisindex + 1).children('.bot').html('<input type="button" value="提交报单" class="done"/>');
            } else {
                $("#service_packing_other .other").eq(thisindex + 1).children('.bot').html('<input type="button" value="下一步" class="next"/>');
            }
        } else if (thisindex === thiscount - 1) {
            // 最后的
            if (thiscount === 2) {
                // 剩两个
                $("#service_packing_other .other").eq(thisindex - 1).children('.bot').html('<input type="button" value="提交报单" class="done"/>');
            } else {
                $("#service_packing_other .other").eq(thisindex - 1).children('.bot').html('<input type="button" value="上一步" class="prev"/><input type="button" value="提交报单" class="done"/>');
            }
        }
        // 激活状态
        if (thisindex === thisnonce) {
            if (thisindex === 0) {
                $("#service_packing_other .top a").eq(thisindex + 1).addClass('on')
                $("#service_packing_other .other").eq(thisindex + 1).addClass('on');
            } else if (thisindex === thiscount - 1) {
                $("#service_packing_other .top a").eq(thisindex - 1).addClass('on')
                $("#service_packing_other .other").eq(thisindex - 1).addClass('on');
            } else {
                $("#service_packing_other .top a").eq(thisindex - 1).addClass('on')
                $("#service_packing_other .other").eq(thisindex - 1).addClass('on');
            }
        }
        $("#service_packing_other .top a").eq(thisindex).remove();
        $("#service_packing_other .other").eq(thisindex).remove();
        // 阻止冒泡和冲绑事件
        event.stopPropagation();
        BindFormEvent();
    });
}

// 调用数据接口
+ function() {
    // 设置下载链接
    $("#doclink").attr("href", ITSMLINK + "uploadFile/global/IT设备使用管理制度4-15版CN.doc");
    $("#xlslink").attr("href", ITSMLINK + "uploadFile/201709/72149837577509151331.xls");
    var CommonSucceed = AjaxComplete(9);
    if (GetUrlParam("type")) {
        var thistype = GetUrlParam("type");
        // 直接去到预览页面?
        /*RequestGTMC("listDoingIncidentByUserId", {},
        function(json) {
        console.log("处理列表 获取成功", json);
        if (json.content) {
        for (var i = 0; i < json.content.length; i++) {
        if(thistype === json.content[i].type_code) {
        console.log(thistype, json.content[i].type_code, thistype === json.content[i].type_code);
        window.location.href = "terms_adress.html?code=" + json.content[i].code;
        }
        }
        }
        });*/
        if (thistype.indexOf("itUse") > -1 || thistype.indexOf("ItUse") > -1) {
            $(".common_shadow").addClass('activate').children('.detail_popup_clause.ituse').addClass('activate');
        }
        if (thistype.indexOf("accountIntranet") > -1 || thistype.indexOf("AccountIntranet") > -1) {
            $(".common_shadow").addClass('activate').children('.detail_popup_clause.intranet').addClass('activate');
        }
        $("#btnSubmit").click(function(){
        	var submitForm = document.getElementById('submitForm');
        	var formParam = $("#submitForm").serialize();//序列化表格内容为字符串  
            $.ajax({  
                type:'post',      
                url:ITSMLINK+"individuation/individuation/requestSaveOrUpdate",
                data:formParam,  
                cache:false,  
                dataType:'json',  
                success:function(json){
                	if (json.success && json.success === true) {
                       // window.location.href = "terms_adress.html?code=&tier=";
                    } else {
                        $(".common_shadow").addClass('activate').children(".detail_popup_verify").addClass('activate fail');
                        $(".detail_popup_verify .word").html("报单失败，请及时与IT服务台联系，联系电话：020-39398800。");
                        $(".detail_popup_verify .back a").attr('href', 'index.html').html("返回首页");
                    }
                }  
            });
        });
        
        // 获取服务表单
        RequestGTMC("listRequestByReqType", {
                reqType: thistype
            },
            function(json) {
                console.log("主要表单 获取成功");
                console.log(json);
                
                if (json.success && json.data) {
                    var str, $form = $("#service_packing_form");
                    $form.empty();
                    
                    str = '<div class="detail_top_table"><h1 class="title">code--</h1><span class="time"></span><div class="sub"><h2>申报表单</h2><div class="dot"></div></div><dd class="service_packing_submit fake" style="max-height: ' + (window.innerHeight - 244) + 'px;" data-form="">' + json.data.chtml + '<div class="common_file_upload num"><span class="upload_title">附件：</span><a href="javascript:" class="upload_sel">上传附件<input id="fileupload" class="num" type="file" multiple></a><ul class="upload_list"></ul><span class="upload_tips">支持格式：<br />jpg,gif,png,jpeg,txt,doc,docx,xls,xlsx,pdf,zip,rar,msg,eml,csv,tif</span></div></dd></div><img src="' + (json.data.imgSrc ? ITSMLINK + json.data.imgSrc : '../images/itsf_detail_photo.jpg') + '" class="photo">';
                    /*str = '<img src="' + (json.data.imgSrc ? ITSMLINK + json.data.imgSrc : '../images/itsf_detail_photo.jpg') + '" class="photo"><div class="detail_top_table"><h1 class="title">' + json.data.code + '</h1><span class="time">你的服务大约在 <em>' + json.data.objectTime + '</em>小时内完成</span><div class="sub"><h2>申报表单</h2><div class="dot"></div></div><dd class="service_packing_submit fake" data-form="' + json.data.reqType + '">' + json.data.scriptContent + '</dd></div>';*/
                    $form.html(str);
                    // InputDataVerify();
                    $("#service_packing_info .show .info").html("description--");
                    // 上传链接
                    var namelist = new Array(),
                        acceptFileTypes = /(jpg|gif|png|jpeg|txt|doc|docx|xls|xlsx|ppt|pptx|pdf|zip|rar|apk|msg|eml|csv|tif)$/i,
                        thissource = $('input[name="itemId"]:eq(0)').val();
                    $('#fileupload.num').fileupload({
                        url: ITSMLINK + 'fileUpload?sourceId=' + thissource,
                        autoUpload: false,
                        dataType: "json",
                        add: function(e, data) {
                            // 去重名
                            if (namelist.indexOf(data.files[0].name) === -1) {
                                // 限格式
                                if (acceptFileTypes.test(data.files[0].name.split(".")[data.files[0].name.split(".").length - 1])) {
                                    // 限大小
                                    if (data.originalFiles[0]['size'] < 15728640) {
                                        /*$(".common_file_upload.num .upload_list").addClass('activate').append('<li><span class="act">' + data.files[0].name + '</span></li>');
                                        $("<a/>").appendTo($(".common_file_upload.num .upload_list li:last")).attr({
                                        "href": "javascript:",
                                        "class": "del"
                                        }).on('click', function(event) {
                                        var arrindex = $(this).parent().index();
                                        namelist.splice(arrindex, 1);
                                        $(this).parent().remove();
                                        console.log(namelist, e, data);
                                        });
                                        $("<a/>").appendTo($(".common_file_upload.num .upload_list li:last")).attr({
                                        "href": "javascript:",
                                        "class": "hid"
                                        }).on('click', function(event) {
                                        data.submit();
                                        });
                                        namelist.push(data.files[0].name);*/
                                        // 保证复制和原本表单功能一致
                                        $(".common_file_upload.num").each(function(index, el) {
                                            $(el).find(".upload_list").addClass('activate').append('<li><span class="act">' + data.files[0].name + '</span></li>');
                                            $("<a/>").appendTo($(el).find(".upload_list li:last")).attr({
                                                "href": "javascript:",
                                                "class": "del"
                                            }).on('click', function(event) {
                                                var arrindex = $(this).parent().index();
                                                namelist.splice(arrindex, 1);
                                                $(this).parent().remove();
                                                console.log(namelist, e, data);
                                            });
                                            $("<a/>").appendTo($(el).find(".upload_list li:last")).attr({
                                                "href": "javascript:",
                                                "class": "hid"
                                            }).on('click', function(event) {
                                                data.submit();
                                            });
                                        });
                                        namelist.push(data.files[0].name);
                                    } else {
                                        $(".common_shadow").addClass('activate').children('.detail_popup_prompt').addClass('activate').find('.word').html("请核对上传文件大小是否超过 15M 。");
                                    }
                                } else {
                                    $(".common_shadow").addClass('activate').children('.detail_popup_prompt').addClass('activate').find('.word').html("请核对上传文件格式是否符合。");
                                }
                            } else {
                                $(".common_shadow").addClass('activate').children('.detail_popup_prompt').addClass('activate').find('.word').html("请核对上传文件名称是否相同。");
                            }
                            console.log(namelist, e, data);
                            console.log(data.originalFiles[0]['size'], (data.originalFiles[0]['size'] < 15728640), data.files[0].name.split(".")[data.files[0].name.split(".").length - 1], acceptFileTypes.test(data.files[0].name.split(".")[data.files[0].name.split(".").length - 1]), data.files[0].name.split(".").length, data.originalFiles[0]['type']);
                        },
                        done: function(e, data) {
                            console.log("upload succeed", data.files[0].name, data.url);
                            console.log(e, data);
                            AddUpload();
                        }
                    });
                    if (thistype.indexOf("pack") === 0) {
                        $(".common_file_upload").remove();
                        $(".detail_top_table .sub h2").html('申报说明');
                    }
                    // 获取个人信息
                    /*var code = $("#common_myself_name").attr('data-code');
                    RequestGTMC("listAppUserByTerm", {term: code},
                        function(json) {
                            console.log("个人信息 查询成功", json, code);
                            if (json.length > 0) {
                                var $el = $("#service_packing_user");
                                if (json[0].fullname !== undefined && json[0].fullname !== null) {
                                    $el.find('.name').val(json[0].fullname).attr('data-name', json[0].fullname);
                                }
                                if (json[0].code !== undefined && json[0].code !== null) {
                                    $el.find('.code').val(json[0].code).attr('data-code', json[0].code);
                                }
                                if (json[0].fullname !== undefined && json[0].fullname !== null) {
                                    $el.find('.fullname').val(json[0].fullname).attr('data-fullname', json[0].fullname);
                                }
                                if (json[0].mobile_short !== undefined && json[0].mobile_short !== null) {
                                    $el.find('.mobile_short').val(json[0].mobile_short).attr('data-mobile_short', json[0].mobile_short);
                                }
                                if (json[0].telno !== undefined && json[0].telno !== null) {
                                    $el.find('.telno').val(json[0].telno).attr('data-telno', json[0].telno);
                                }
                                if (json[0].email !== undefined && json[0].email !== null) {
                                    $el.find('.email').val(json[0].email).attr('data-email', json[0].email);
                                }
                                if (json[0].mobile !== undefined && json[0].mobile !== null) {
                                    $el.find('.mobile').val(json[0].mobile).attr('data-mobile', json[0].mobile);
                                }
                                if (json[0].department_treenode_name_path !== undefined && json[0].department_treenode_name_path !== null) {
                                    $el.find('.department_treenode_name_path').val(json[0].department_treenode_name_path).attr('data-department_treenode_name_path', json[0].department_treenode_name_path);
                                }
                            }
                        });*/
                }
                AddDoneCount();
            },
            function() {
                console.log("主要表单 调用失败");
            },
            function() {
                console.log("主要表单 请求完成");
            });
        // 获取相关服务列表
        RequestGTMC("listRelateRequestByReqType", {
                reqType: thistype
            },
            function(json) {
                console.log("相关服务 获取成功");
                console.log(json);
                if (json.success && json.data) {
                    var str = "",
                        $more = $("#service_packing_more");
                    $more.empty();
                    for (var i = 0; i < json.data.length; i++) {
                        str += '<li><img src="' + (json.data[i].toImg ? ITSMLINK + json.data[i].toImg : '../images/itsf_detail_head1.jpg') + '"><div class="box"><span class="checkbox_detail' + (json.data[i].checked ? ' checked' : '') + '" data-type="' + json.data[i].toType + '"></span><label>' + json.data[i].toName + '</label></div></li>';
                    }
                    if (json.data.length === 0) {
                        $(".detail_mid").addClass('onedata');
                    }
                    str += '<input type="submit" value="立即报单" class="refer">';
                    $more.html(str);
                    //detail 相关服务的checkbox
                    if (thistype.indexOf("pack") === 0) {
                        $more.find('.checkbox_detail').on('click', function(event) {
                            if ($(this).hasClass('checked')) {
                                $(this).removeClass('checked');
                                if ($more.find('.checkbox_detail.checked').length === 0) {
                                    ShowVerifyTips("请选择至少一项服务。");
                                    $(this).addClass('checked');
                                }
                            } else {
                                $(this).addClass('checked');
                            }
                        });
                    } else {
                        $more.find('.checkbox_detail').on('click', function(event) {
                            if ($(this).hasClass('checked')) {
                                $(this).removeClass('checked');
                            } else {
                                $(this).addClass('checked');
                            }
                        });
                    }
                    //弹出表单
                    $(".common_content.detail .detail_mid .refer").on('click', function(event) {
                        // 正确计数
                        /*var required = 0;
                        $("#service_packing_form .required-tip").each(function(index1, el1) {
                        $(el1).parent().find('input:not([type="hidden"])').each(function(index2, el2) {
                        if ($(el2).val() === "") {
                        required = -9999;
                        } else {
                        required++;
                        }
                        console.log("检查", required, $(el2).val(), el2);
                        });
                        $(el1).parent().find('textarea:not(.ban)').each(function(index3, el3) {
                        if ($(el3).val() === "") {
                        required = -9999;
                        } else {
                        required++;
                        }
                        console.log("检查", required, $(el3).val(), el3);
                        });
                        });
                        if (required >= 0) {
                        var $el = $("#service_packing_more .box .checkbox_detail.checked");
                        if ($el && $el.length > 0) {
                        $("#service_packing_other").empty();
                        $el.each(function(index, el) {
                        GetOtherService($(this).attr('data-type'), (index + 1), $el.length);
                        });
                        $(".common_shadow").addClass('activate').children('.common_adaptation').addClass('activate').children('.termsAdress_declaration').addClass('on');
                        } else {
                        //确认提交表单
                        FillApplicantInfo ();
                        }
                        } else {
                        alert("请核对当前表单中必填项是否已全部填写");
                        }*/
                        var $sel = $("#service_packing_more .box .checkbox_detail.checked"),
                            $old = $("#service_packing_form"),
                            form = '<span class="pic"><i>&#215;</i><img src="' + $old.find('.photo').attr('src') + '"></span><span class="picName">' + $old.find('.title').html() + '</span>';
                        if ($sel && $sel.length > 0) {
                            // 绑定多个报单
                            if (thistype.indexOf("pack") === 0) {
                                form = '<div class="top"></div>';
                                $("#service_packing_other").html(form).prepend('<div class="common_load"><img src="../images/loading.gif"></div>');
                            } else {
                                form = '<div class="top"><a class="on" href="javascript:">' + form + '</a></div><div class="other on"><dl class="center"><dt><p>' + $old.find('.title').html() + '</p></dt><dd class="attention">请核对必填项是否已全部填写</dd></dl><div class="bot"><input type="button" value="下一步" class="next"/></div></div>';
                                $("#service_packing_other").html(form).prepend('<div class="common_load"><img src="../images/loading.gif"></div>').find('.other .center').append($old.find('.service_packing_submit').clone(true).removeClass('fake'));
                            }
                            $(".common_shadow").addClass('activate').children('.common_adaptation').addClass('activate').children('.termsAdress_declaration').addClass('on');
                            $sel.each(function(index, el) {
                                var nowtype = $(this).attr('data-type');
                                if (nowtype.indexOf("itUse") > -1 || nowtype.indexOf("ItUse") > -1) {
                                    $(".common_shadow").addClass('activate').children('.detail_popup_clause.ituse').addClass('activate');
                                }
                                if (nowtype.indexOf("accountIntranet") > -1 || nowtype.indexOf("AccountIntranet") > -1) {
                                    $(".common_shadow").addClass('activate').children('.detail_popup_clause.intranet').addClass('activate');
                                }
                                console.log("阻止异步：", nowtype, $sel.length)
                                if (thistype.indexOf("pack") === 0) {
                                    GetOtherService(nowtype, $sel.length);
                                } else {
                                    GetOtherService(nowtype, $sel.length + 1);
                                }
                            });
                            $(".common_shadow").addClass('activate').children('.common_adaptation').addClass('activate').children('.termsAdress_declaration').addClass('on');
                        } else {
                            /*form = '<div class="top"><a class="on" href="javascript:">' + form + '</a></div><div class="other on"><dl class="center"><dt><p>' + $old.find('.title').html() + '</p></dt><dd class="attention">请核对必填项是否已全部填写</dd></dl><div class="bot"><input type="button" value="提交表单" class="done"/></div></div>';
                                $("#service_packing_other").html(form).find('.other .center').append($old.find('.service_packing_submit').clone(true).removeClass('fake'));
                                $(".common_shadow").addClass('activate').children('.common_adaptation').addClass('activate').children('.termsAdress_declaration').addClass('on');
                                BindFormEvent();
                            var required = 0;
                            $(".service_packing_submit").removeClass('fake');
                            $old.find(".required-tip").each(function(index1, el1) {
                                $(el1).parent().find('input:not([type="hidden"]):not(.ban)').each(function(index2, el2) {
                                    if ($(el2).val() === "") {
                                        required = -9999;
                                    } else {
                                        required++;
                                    }
                                    console.log("检查", required, $(el2).val(), el2);
                                });
                                $(el1).parent().find('textarea:not(.ban)').each(function(index3, el3) {
                                    if ($(el3).val() === "") {
                                        required = -9999;
                                    } else {
                                        required++;
                                    }
                                    console.log("检查", required, $(el3).val(), el3);
                                });
                                $(el1).parent().find('select:not(.ban)').each(function(index4, el4) {
                                    if (el4.selectedIndex === 0) {
                                        required = -9999;
                                    } else {
                                        required++;
                                    }
                                    console.log("检查", required, $(el4).val(), el4);
                                });
                            });
                            $old.find(".requiredprompt").each(function(index1, el1) {
                                $(el1).parent().find('input:not([type="hidden"]):not(.ban)').each(function(index2, el2) {
                                    if ($(el2).val() === "") {
                                        required = -9999;
                                    } else {
                                        required++;
                                    }
                                    console.log("检查", required, $(el2).val(), el2);
                                });
                                $(el1).parent().find('textarea:not(.ban)').each(function(index3, el3) {
                                    if ($(el3).val() === "") {
                                        required = -9999;
                                    } else {
                                        required++;
                                    }
                                    console.log("检查", required, $(el3).val(), el3);
                                });
                                $(el1).parent().find('select:not(.ban)').each(function(index4, el4) {
                                    if (el4.selectedIndex === 0) {
                                        required = -9999;
                                    } else {
                                        required++;
                                    }
                                    console.log("检查", required, $(el4).val(), el4);
                                });
                            });
                            if (required >= 0) {
                                //确认提交表单
                                FillApplicantInfo();
                            } else {
                                //alert("请核对当前表单中必填项是否已全部填写");
                                $(".common_shadow").addClass('activate').children('.detail_popup_prompt').addClass('activate').find('.word').html("请核对当前表单中必填项是否已全部填写。");
                            }*/
                            // 只有一个报单
                            if (CheckServiceContent($old, true) === undefined) {
                                //确认提交表单
                                $(".service_packing_submit").removeClass('fake');
                                FillApplicantInfo();
                            }
                        }
                    });
                    //点击文字选择
                    $(".common_content.detail .box label").on('click', function(event) {
                        $(this).siblings('.checkbox_detail').trigger('click');
                    });
                    //关闭表单
                    $(".common_shadow .termsAdress_declaration .close").on('click', function(event) {
                        $(".common_shadow").removeClass('activate').children('.common_adaptation').removeClass('activate').children('.termsAdress_declaration').removeClass('on');
                        $("#service_packing_other").empty();
                    });
                }
                AddDoneCount();
            },
            function() {
                console.log("相关服务 调用失败");
            },
            function() {
                console.log("相关服务 请求完成");
            });
        // 获取服务总评价
        RequestGTMC("listOverallComment", {
                reqType: thistype
            },
            function(json) {
                console.log("服务总评 获取成功");
                console.log(json);
                if (json) {
                    var $mark = $("#service_packing_info .detail_bottom_review .please"),
                        sub, str = '',
                        grade1 = parseFloat(json.satisfactionquality) || 5,
                        grade2 = parseFloat(json.satisfactionapproach) || 5,
                        grade3 = parseFloat(json.satisfactiontimely) || 5;
                    $mark.empty();
                    str += '<div class="point"><h1>服务满意度</h1><h2>' + ((grade1 + grade2 + grade3) / 3).toFixed(1) + '</h2><h3></h3></div><ol class="all"><li><h4>技术水平：</h4><ol class="review_star">';
                    for (sub = 1; sub <= 5; sub++) {
                        if (sub <= grade1) {
                            str += '<li class="yes"></li>';
                        } else {
                            str += '<li></li>';
                        }
                    }
                    str += '</ol><h5>' + grade1 + '分</h5></li><li><h4>服务态度：</h4><ol class="review_star">';
                    for (sub = 1; sub <= 5; sub++) {
                        if (sub <= grade2) {
                            str += '<li class="yes"></li>';
                        } else {
                            str += '<li></li>';
                        }
                    }
                    str += '</ol><h5>' + grade2 + '分</h5></li><li><h4>服务的及时性：</h4><ol class="review_star">';
                    for (sub = 1; sub <= 5; sub++) {
                        if (sub <= grade3) {
                            str += '<li class="yes"></li>';
                        } else {
                            str += '<li></li>';
                        }
                    }
                    str += '</ol><h5>' + grade3 + '分</h5></li></ol>';
                    $mark.html(str);
                }
                $("#service_packing_info .detail_review_content .res").html('<div class="common_none detail">暂无任何相关评论</div>');
                $("#service_packing_info .detail_bottom_review .more").hide();
                AddDoneCount();
                AddAppraise();
            },
            function() {
                console.log("服务总评 调用失败");
            },
            function() {
                console.log("服务总评 请求完成");
            });
        // 查看打包服务详情
        /*RequestGTMC("listRequestByCode", {
        code : 5323945398854890766
        },
        function(json) {
        console.log("评价详情 获取成功");
        console.log(json);
        if (json.success && json.data) {
        var str = '', $form = $("");
        $form.empty();
        for (var i = 0; i < json.data.length; i++) {
        str += json.data[i];
        }
        $form.html(str);
        }
        AddDoneCount();
        },
        function() {
        console.log("评价详情 调用失败");
        },
        function() {
        console.log("评价详情 请求完成");
        });*/
        if (GetUrlParam("tier")) {
            var time = 0,
                link = '<a href="index.html">首页</a>',
                head = GetUrlParam("tier").split("$");
            for (; time < head.length - 1; time++) {
                link += '><a href="javascript:">' + head[time] + '</a>';
            }
            link += '><a href="javascript:" class="activate">' + head[time] + '</a>';
            $("#service_packing_link").html(link);
        }
    } else {
        $(".common_main").html('<div class="common_none detail">暂无任何相关报单</div>');
        $(".common_main").css('height', document.body.clientHeight - $(".common_head").height() - 108);
        $(".common_float").css('bottom', document.body.clientHeight - $(".common_foot").offset().top + 38);
    }
}();

// 事件绑定
- function() {
    // 加载不同评论
    $(".detail_review_content .bar input[type='radio']").on('click', function(event) {
        if ($(this).siblings('span').html().indexOf("(0)") === -1) {
            $("#service_packing_info .detail_review_content .res").html('<div class="common_load detail"><img src="../images/loading.gif"></div>');
            $("body").prepend('<div class="common_load full"><img src="../images/loading.gif"></div>');
            AddAppraise();
            $("#service_packing_info .detail_bottom_review .more").hide();
        } else {
            $("#service_packing_info .detail_review_content .res").html('<div class="common_none detail">暂无任何相关评论</div>');
            $("#service_packing_info .detail_bottom_review .more").hide();
            NoneAppraise();
        }
    });
    // 加载更多评论
    $(".common_content.detail .detail_bottom_review .more").on('click', function(event) {
        $("#service_packing_info .detail_review_content .res").append('<div class="common_load detail"><img src="../images/loading.gif"></div>');
        $("body").prepend('<div class="common_load full"><img src="../images/loading.gif"></div>');
        $("#service_packing_info .detail_bottom_review .more").hide();
        AddAppraise();
    });
    // detail_popup_clause 的checkbox
    $('.detail_popup_clause .checkB_prop').on('click', function(event) {
        if ($(this).hasClass('checked')) {
            $(this).removeClass('checked').parent().siblings('.term_bottom').children('.submit').removeClass('allow');
        } else {
            $(this).addClass('checked').parent().siblings('.term_bottom').children('.submit').addClass('allow');;
        }
    });
    // 同意协议
    $(".common_shadow .detail_popup_clause .term_bottom").on('click', '.submit', function(event) {
        if ($(".common_shadow .confirm .checkB_prop").hasClass("checked")) {
            console.log($(".common_shadow .confirm .checkB_prop").has(".checked"), $(".common_shadow .confirm .checkB_prop").hasClass("checked"))
            console.log($(this).parents(".detail_popup_clause").siblings('.activate').length > 0);
            if ($(this).parents(".detail_popup_clause").siblings('.activate').length > 0) {
                $(this).parents(".detail_popup_clause").removeClass('activate');
            } else {
                $(".common_shadow").removeClass('activate').children('.detail_popup_clause').removeClass('activate');
            }
        }
    });
    // 显示协议
    if ($(".common_warning")) {
        $(".common_warning").off("click").siblings('.detail_popup_clause').removeClass('activate');
        $(".common_warning").on('click', function(event) {
            $(this).parent().children('.detail_popup_clause').addClass('activate');
            $(this).remove();
        });
    }
    //勾选样式
    /*$(".common_content.detail .detail_mid .check").on('click', 'input[type="checkbox"]', function(event) {
    if($(this).hasClass('checked')) {
    $(this).removeAttr('class');
    } else {
    $(this).addClass('checked');
    }
    });*/
    //关闭协议
    $(".common_shadow .detail_popup_clause .close").on('click', function(event) {
        console.log($(this).parents(".detail_popup_clause").siblings('.activate').length > 0);
        if ($(this).parents(".detail_popup_clause").siblings('.activate').length > 0) {
            $(".common_shadow").removeClass('activate').children('.activate').removeClass('activate');
        } else {
            window.location.href = "index.html";
        }
    });
    // 底部切换
    /*$(".detail_bottom .card li:eq(0)").addClass('activate');
    $(".detail_bottom .show li:eq(0)").addClass('activate');
    $(".common_content.detail .detail_bottom .card").on('click', 'li', function(event) {
        $(this).addClass('activate').siblings('li').removeAttr('class');
        $(".detail_bottom .show li").eq($(this).index()).addClass('activate').siblings('li').removeClass('activate');
    });*/
    $(".detail_bottom .card li:eq(1)").addClass('activate').siblings().hide();
    $(".detail_bottom .show li:eq(1)").addClass('activate').siblings().hide();
    //右侧回到顶部
    $(".common_float .rbtn1").on('click', function(event) {
        if ($("html").scrollTop()) {
            $("html").animate({
                scrollTop: 0
            }, 1000);
            return false;
        } else {
            $('body').animate({
                scrollTop: 0
            }, 1000);
            return false;
        }
    });
    // 其他表单切换
    /*var $oDecla = $('.termsAdress_declaration .top>a');
    $oDecla.click(function() {
        var n = $(this).index();
        $(this).addClass('on').siblings('a').removeClass('on');
        $(this).parent().siblings('.other').eq(n).addClass('on').siblings('.other').removeClass('on').children('.center').removeClass('border_active');
        //red_border_prop
        myCheck();
    });
    function myCheck() {
        $('.termsAdress_declaration form.on .bot').children().click(function() {
            var oStar = $('.termsAdress_declaration form.on .mark');
            var oDval = $('.termsAdress_declaration form.on .ipt_down').children('input').val();
            var oUval = $('.termsAdress_declaration form.on .ipt_up').children('input').val();
            var oSval = $('.termsAdress_declaration form.on .ipt_sel').val();
            var nums = 0;
            for (var i = 0; i < oStar.length; i++) {
                if (oStar.eq(i).parent('label').siblings('input').val() != '') {
                    if ((oDval != '') && (oUval != '')) {
                        nums++;
                        console.log(i + "nums:" + nums);
                        if (nums == oStar.length) {
                            $('.termsAdress_declaration form.on>.center').removeClass('border_active');
                        }
                    } else {
                        $('.termsAdress_declaration form.on>.center').addClass('border_active');
                    }
                } else {
                    $('.termsAdress_declaration form.on>.center').addClass('border_active');
                }
            }
        });
    }
    myCheck();*/
    //termsAdress_declaration 弹框 option下拉选择
    $('.ipt_option input').click(function() {
        $(this).siblings('.options').toggle();
    });
    $('.options i').click(function() {
        var oTxt = $(this).html();
        $(this).parent().siblings('input').val(oTxt)
    });
    //declaration 申请内容选择
    $('.termsAdress_declaration .td_select a').click(function() {
        $(this).addClass('on').siblings('a').removeClass('on');
    });
    // 提示弹窗
    $(".detail_popup_prompt .back a").on('click', function(event) {
        // $(".common_shadow").removeClass('activate').children('.detail_popup_prompt').removeClass('activate');
        var el = $(this).parents(".detail_popup_prompt");
        el.removeClass('activate');
        console.log(el.siblings('.activate').length, el.siblings('.activate').length <= 0);
        if (el.siblings('.activate').length <= 0) {
            el.parent().removeClass('activate');
        }
    });
    // 验证弹窗
    $(".detail_popup_verify .back a").on('click', function(event) {
        var el = $(this).parents(".detail_popup_verify");
        el.removeClass('activate');
        console.log(el.siblings('.activate').length, el.siblings('.activate').length <= 0);
        if (el.siblings('.activate').length <= 0) {
            // 没有其他弹窗就关闭父级
            el.parent().removeClass('activate');
        } else {
            // 有其他弹窗就只关闭自己
            el.removeAttr('style');
        }
    });
    // 关闭内嵌弹窗
    $(".detail_popup_widget .widget_control .can").on('click', function(event) {
        $("#service_packing_tree").removeAttr('data-tmp').empty();
        var el = $(this).parents(".detail_popup_widget");
        el.removeClass('activate');
        console.log(el.siblings('.activate').length, el.siblings('.activate').length <= 0);
        // 如果只有一个弹窗就关闭遮罩
        if (el.siblings('.activate').length <= 0) {el.parent().removeClass('activate');}
    });
    // 管理地址按钮
    var thistype = GetUrlParam("type"),
        thistier = GetUrlParam("tier");
    if (thistype && thistier) {
        $(".common_popup_applicant .select .setAdress").attr('href', 'my_address.html?type=' + thistype + '&tier=' + thistier);
    }
    // 申报人点确认
    $(".common_popup_applicant .commit").on('click', function(event) {
        $(".common_shadow").removeClass('activate').children('.common_popup_applicant').removeClass('activate');
        SubmitAllFormData();
    });
}();